﻿<%@ Page Language="C#" AutoEventWireup="true" CodeFile="List.aspx.cs" Inherits="SysAdmin_Dictionary_List" %>

<!DOCTYPE html>

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <title></title>
</head>
<body>
    <script type="text/javascript">
        $(function () {
            $('#dictionary_datagrid').datagrid({
                url: 'Dictionary/List.aspx?paramType=QueryList',
                fit: true,
                fitColumns: true,
                border: false,
                pagination: true,
                idField: 'ID',
                pageSize: 30,
                pageList: [10, 20, 30, 40, 50],
                sortName: 'text',
                sortOrder: 'asc',
                checkOnSelect: false,
                selectOnCheck: false,
                nowrap: false,
                frozenColumns: [[{
                    title: '编号',
                    field: 'ID',
                    width: 150,
                    sortable: true,
                    checkbox: true
                }, {
                    title: '字典标识',
                    field: 'dicKey',
                    width: 150,
                    sortable: true
                }]],
                columns: [[{
                    title: '字典名称',
                    field: 'dicName',
                    width: 300,
                }, {
                    title: '排序数字',
                    field: 'indexNum',
                    width: 100,
                },
                {
                    title: '是否可用',
                    field: 'isActive',
                    width: 100,

                }, {
                    field: 'tempTxt',
                    title: '动作',
                    width: 300,
                    formatter: function (value, row, index) {
                        var strReturn = "";
                        if (row.parentKey == 'Root') {
                            strReturn += '<span style="color:blue;cursor: pointer;"  onclick="ShowChildDicList(\'' + row.dicKey + '\')" >' + '下一级字典' + '</span>&nbsp;&nbsp; ';
                        }
                        else {
                            strReturn += '<span style="color:blue;cursor: pointer;"  onclick="ShowRootDicList()" >' + '上一级字典' + '</span>&nbsp;&nbsp; ';
                        }
                        return formatString(strReturn + '<img onclick="sysadmin_dictionary_edit(\'{0}\');" src="{1}"/>&nbsp;<img onclick="sysadmin_rdictionary_del(\'{2}\');" src="{3}"/>', row.ID, 'Images/pencil.png', row.ID, 'Images/cancel.png');

                    }
                }]],
                toolbar: [{
                    text: '根列表',
                    iconCls: 'icon-undo',
                    handler: function () {
                        ShowRootDicList();
                    }
                }, '-', {
                    text: '增加',
                    iconCls: 'icon-add',
                    handler: function () {
                        sysadmin_dictionary_add();
                    }
                }, '-'
                //, {
                //    text: '批量删除',
                //    iconCls: 'icon-remove',
                //    handler: function () {
                //        sysadmin_role_remove();
                //    }
                //}, '-'
                ]
            });
        });

        //显示下一级字典列表
        function ShowChildDicList(dic_key) {
            document.getElementById("dic_list_par_key").value = dic_key;
            $('#dictionary_datagrid').datagrid('load', { parCode: document.getElementById('dic_list_par_key').value });
        }

        //显示根目录字典列表
        function ShowRootDicList() {
            document.getElementById("dic_list_par_key").value = "Root";
            $('#dictionary_datagrid').datagrid('load', { parCode: document.getElementById('dic_list_par_key').value });
        }

        //添加字典
        function sysadmin_dictionary_add() {
            $('<div/>').dialog({
                href: 'Dictionary/Add.aspx?dic_key=' + document.getElementById("dic_list_par_key").value,
                width: 500,
                height: 200,
                modal: true,
                title: '添加字典',
                buttons: [{
                    text: '增加',
                    iconCls: 'icon-add',
                    handler: function () {

                        var d = $(this).closest('.window-body');
                        $('#admin_dictionary_addForm').form('submit', {
                            url: 'Dictionary/List.aspx?paramType=AddModel',
                            success: function (result) {
                                try {
                                    var r = $.parseJSON(result);
                                    if (r.success) {
                                        $('#dictionary_datagrid').datagrid('load', { parCode: document.getElementById('dic_list_par_key').value });
                                        d.dialog('destroy');
                                    }
                                    $.messager.show({
                                        title: '提示',
                                        msg: r.msg
                                    });
                                } catch (e) {
                                    $.messager.alert('提示', result);
                                }
                            }
                        });
                    }
                }],
                onClose: function () {
                    $(this).dialog('destroy');
                }
            });
        }

        //编辑字典
        function sysadmin_dictionary_edit(dictionary_key) {
            $('<div/>').dialog({
                href: 'Dictionary/Edit.aspx?dic_key=' + dictionary_key,
                width: 500,
                height: 200,
                modal: true,
                title: '字典编辑',
                buttons: [{
                    text: '编辑',
                    iconCls: 'icon-add',
                    handler: function () {
                        var d = $(this).closest('.window-body');
                        $('#admin_dictionary_editForm').form('submit', {
                            url: 'Dictionary/List.aspx?paramType=UpdateModel',
                            success: function (result) {
                                try {
                                    var r = $.parseJSON(result);
                                    if (r.success) {
                                        d.dialog('destroy');
                                        $('#dictionary_datagrid').datagrid('load', { parCode: document.getElementById('dic_list_par_key').value });
                                    }
                                } catch (e) {

                                    $.messager.alert('提示', "增加失败，请重试！");
                                }
                            }
                        });
                    }
                }],
                onClose: function () {
                    $(this).dialog('destroy');
                }
            });
        }

        //删除字典
        function sysadmin_rdictionary_del(dictionary_key) {

            $.messager.confirm('提示', '你确定要删除该行数据么?', function (r) {
                if (r) {
                    $.ajax({
                        type: "POST",
                        url: 'Dictionary/List.aspx',
                        data: "paramType=DelModel&dicCode=" + dictionary_key,
                        dataType: "json",
                        success: function (msg) {
                            if (msg.success) {
                                $('#dictionary_datagrid').datagrid('load', { parCode: document.getElementById('dic_list_par_key').value });
                            }
                        },
                        error: function (e, ex) {
                            $.messager.alert('错误提示', '删除失败！');
                        }

                    });
                }
            });
        }

    </script>
    <table id="dictionary_datagrid"></table>
    <input id="dic_list_par_key" type="hidden" value="Root" />
</body>
</html>
